const apiList = {
  generateTestCase: "/generateTestCase",
  generateInterface: "/generateInterface",
  generateJmxScript: "/generateJmxScript",
  generateJmxScriptFile: "/generateJmxScriptFile",
  downloadFile: "/downloadFile",
  generateInterfaceDocInXxsj: "/generateInterfaceDocInXxsj",
}
let host = location.origin

axios.defaults.baseURL = host

// 添加响应拦截器
axios.interceptors.response.use(function (response) {
  // 对响应数据做点什么
  let data = response.data
  if (data.code !== '0') {
    return Promise.reject(new Error(data.message));
  }
  return data.data;
}, function (error) {
  let response = error.response
  if (response) {
    if (response.data) {
      return Promise.reject(new Error(response.data.message));
    }
  }
  return Promise.reject(error);
});

window.$api = new Proxy({}, {
  get(target, p, receiver) {
    return (data) => {
      return axios.post(apiList[p], data)
    }
  }
})
